home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Games of Daze
/
Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso
/
x2ftp
/
msdos
/
source
/
zendisk2
/
lst13-8.asm
< prev
next >
Wrap
Assembly Source File
|
1990-02-15
|
1KB
|
58 lines
;
; *** Listing 13-8 ***
;
; Counts the number of negative values in a 1000-word array,
; by comparing each element to 0 and branching accordingly.
;
jmp Skip
;
WordArray label word
X=-500
rept 1000
dw X
X=X+1
endm
WORD_ARRAY_LENGTH equ ($-WordArray)
;
; Counts the number of negative values in a word-sized
; array.
;
; Input:
; CX = length of array in words
; DS:SI = pointer to start of array
;
; Output:
; DX = count of negative values in array
;
; Registers altered: AX, CX, DX, SI
;
; Direction flag cleared
;
; Note: Does not handle arrays that are longer than 32K
; words or cross segment boundaries.
;
CountNegativeWords:
cld
sub dx,dx ;initialize the count to 0
CountNegativeWordsLoop:
lodsw ;get the next word from the array
and ax,ax ;is the word negative?
jns CountNegativeWordsLoopBottom
;not negative-do the next element
inc dx ;word is negative, so increment the
; negative-word counter
CountNegativeWordsLoopBottom:
loop CountNegativeWordsLoop
ret
;
Skip:
call ZTimerOn
mov si,offset WordArray
;point to the array to count
; the # of negative words in...
mov cx,WORD_ARRAY_LENGTH/2
;...set the # of words to check...
call CountNegativeWords
;...and count the negative words
call ZTimerOff